﻿using System;
using THANHTUNGO.Portal.Components.UI;

namespace ITG.Modules.HR
{
    public enum ModulePages
    {
        TimeCard,
        TimeLog,
        Permissions
    }

    public partial class Main : PortalModuleControl
    {
        public override Guid GuidID
        {
            get { return new Guid("{9842BC2D-66BA-4e1a-9987-50A2C1688427}"); }
        }

        private void loadChildControl()
        {
            string m_baseDir = "~/Modules/ITG.HR/";
            string pageQuery = "Page" + this.ModuleID;
            string pageName = Request.QueryString[pageQuery];

            ModulePages page;
            if (pageName == null)
            {
                page = ModulePages.TimeCard;
            }
            else
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", m_baseDir, page);
            if (src.IndexOf("/Mod_") >= 0)
                src = src.Replace("/Mod_", "/Mod/");
            if (src.IndexOf("/Admin_") >= 0)
                src = src.Replace("/Admin_", "/Admin/");
            if (src.IndexOf("/Help_") >= 0)
                src = src.Replace("/Help_", "/Help/");

            YAFPage ctl = (YAFPage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);            
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.loadChildControl();
            if (!IsPostBack)
            {
                this.hlTimeCard.NavigateUrl = YAFUrlBuilder.GetLink(this.ModuleID, ModulePages.TimeCard);
                this.hlTimeLog.NavigateUrl = YAFUrlBuilder.GetLink(this.ModuleID, ModulePages.TimeLog);
                this.hlPermission.NavigateUrl = YAFUrlBuilder.GetLink(this.ModuleID, ModulePages.Permissions);
            }
        }

        protected void btnTimeLog_Click(object sender, EventArgs e)
        {
            YAFUrlBuilder.Redirect(this.ModuleID, ModulePages.TimeLog);
        }
    }
}